from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `detection_records` DROP COLUMN `is_checkin`;
        ALTER TABLE `users` DROP COLUMN `consecutive_days`;
        ALTER TABLE `users` DROP COLUMN `is_checkin`;
        ALTER TABLE `users` DROP COLUMN `checkin_days`;
        ALTER TABLE `users` DROP COLUMN `last_checkin`;
        DROP TABLE IF EXISTS `checkin_records`;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `users` ADD `consecutive_days` INT NOT NULL COMMENT '连续打卡天数' DEFAULT 0;
        ALTER TABLE `users` ADD `is_checkin` BOOL NOT NULL COMMENT '今日是否已打卡' DEFAULT 0;
        ALTER TABLE `users` ADD `checkin_days` INT NOT NULL COMMENT '累计打卡天数' DEFAULT 0;
        ALTER TABLE `users` ADD `last_checkin` DATETIME(6) COMMENT '最后打卡时间';
        ALTER TABLE `detection_records` ADD `is_checkin` BOOL NOT NULL COMMENT '是否已打卡' DEFAULT 0;"""
